import React, { Component } from 'react'

class Counter extends Component {
  // 初始化constructor构造器
  constructor(props) {
      super(props);
      this.handleClickAdd = this.handleClickAdd.bind(this)

      this.state = {
          count: 0,
      };
  }

  handleClickAdd(e) {
      e.preventDefault();
      this.setState({
          count: this.state.count + 1,
      });
  }

  handleClickReduce(e,argu) {
      console.log('自动绑定传参',e,argu);
      this.setState({
          count: this.state.count - 1.5,
      });
  }

  handleClickReset() {
      this.setState({
          count: 100
      })
  }

  render() {
      return (
          <div>
              <p>{this.state.count}</p>
              <button onClick={this.handleClickAdd}>add</button>
              <button onClick={this.handleClickReduce.bind(this,'测试事件绑定')}>reduce</button>
              <button onClick={()=> {this.handleClickReset()}}>reset</button>
          </div>
      )
  }

}

export default Counter